﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace PigLatinTranslator
{
    class EnglishToPigLatinTranslator : Translator
    {
        //Rule for translating from English to Piglatin
        //This first gets one occurence of a vowel starting
        //If that fails then grab the next occuring letter
        const string EnglishToPigRule = @"(^[aeiou]\w*|^y|^\wy|^qu|^\w+?[^aeiou]?){1}|(\G(\w|[\'\-])*[\w'-])";

        public override string translateWord(string Word)
        {
            //English to Pig latin translator
            //Uses regex to break the english word up to follow pig latin translation rules
            MatchCollection WordParts = Regex.Matches(Word, EnglishToPigRule, RegexOptions.IgnoreCase);
            if (WordParts.Count == 2)
            {
                Word = WordParts[1].ToString() + "-" + WordParts[0].ToString() + "ay";
            }
            else
            {
                Word = WordParts[0].ToString() + "-ay";
            }
            //return the word lower case
            return Word.ToLower();
        }

    }
}
